<?php
namespace App\Controllers;

class ExceptionController extends BaseController {

    public function initialize() {
        parent::initialize();
    }

    public function showErrorAction() {
        if(defined('ENVIRONMENT') && ENVIRONMENT == 'development') {
            $this->display('/exception/dev/500', $this->dispatcher->getParams());
        } else {
            if($this->request->isAjax()) {
                $this->sendAjax(false, "请求失败，系统错误！");
            } else {
                //echo "请求失败，系统错误！";
                $this->display('/exception/product/500', $this->dispatcher->getParams());
            }
        }
        exit();
    }

    public function show404Action() {
        if(defined('ENVIRONMENT') && ENVIRONMENT == 'development') {
            $this->dispatcher->setParam('REQUEST_URI', isset($_SERVER['REDIRECT_QUERY_STRING']) ? $_SERVER['REDIRECT_QUERY_STRING'] : $_SERVER['REQUEST_URI']);
            $this->dispatcher->setParam('PHP_SELF', isset($_SERVER['PHP_SELF']) ? $_SERVER['PHP_SELF'] : '');
            $this->dispatcher->setParam('SERVER_NAME', isset($_SERVER['SERVER_NAME']) ? $_SERVER['SERVER_NAME'] : '');
            $this->dispatcher->setParam('SERVER_ADDR', isset($_SERVER['SERVER_ADDR']) ? $_SERVER['SERVER_ADDR'] : '');
            $this->display('/exception/dev/404', $this->dispatcher->getParams());
        } else {
            if($this->request->isAjax()) {
                $this->sendAjax(false, "请求失败，404错误！");
            } else {
                echo "请求失败，404错误！";
            }
        }
        exit();
    }
}